/*    */ package blockbuster.utils.texture;
/*    */ 
/*    */ import blockbuster.utils.ReflectionUtils;
/*    */ import java.awt.image.BufferedImage;
/*    */ import java.io.InputStream;
/*    */ import java.util.ArrayList;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ import java.util.concurrent.ConcurrentHashMap;
/*    */ import net.minecraft.client.Minecraft;
/*    */ import net.minecraft.client.renderer.texture.ITextureObject;
/*    */ import net.minecraft.client.resources.IResourceManager;
/*    */ import net.minecraft.util.ResourceLocation;
/*    */ import net.minecraft.util.Tuple;
/*    */ import org.apache.commons.io.IOUtils;
/*    */ 
/*    */ 
/*    */ public class GifHandler
/*    */ {
/* 20 */   public static Map<ResourceLocation, GifTexture> gifs = new ConcurrentHashMap<>();
/*    */   
/*    */   public static void registerGif(ResourceLocation rl, GifTexture texture) {
/* 23 */     GifTexture old = gifs.remove(rl);
/* 24 */     if (old != null) {
/* 25 */       old.func_147631_c();
/*    */     }
/* 27 */     gifs.put(rl, texture);
/*    */   }
/*    */   
/*    */   public static void removeGif(ResourceLocation location) {
/* 31 */     gifs.remove(location);
/*    */   }
/*    */   
/*    */   public static void bindTexture(ResourceLocation location, int ticks, float partialTicks) {
/* 35 */     Minecraft mc = Minecraft.func_71410_x();
/* 36 */     Map<ResourceLocation, ITextureObject> map = ReflectionUtils.getTextures(mc.field_71446_o);
/* 37 */     if (!map.containsKey(location) && location.func_110623_a().endsWith(".gif")) {
/*    */       try {
/* 39 */         IResourceManager manager = mc.func_110442_L();
/* 40 */         InputStream stream = manager.func_110536_a(location).func_110527_b();
/*    */ 
/*    */         
/* 43 */         List<Tuple<Integer, BufferedImage>> gifImages = getGIFImages(stream);
/*    */         
/* 45 */         GifTexture texture = new GifTexture(location);
/*    */         
/* 47 */         texture.width = ((BufferedImage)((Tuple)gifImages.get(0)).func_76340_b()).getWidth();
/* 48 */         texture.height = ((BufferedImage)((Tuple)gifImages.get(0)).func_76340_b()).getHeight();
/* 49 */         int frames = gifImages.size();
/*    */         
/* 51 */         map.put(location, texture);
/* 52 */         registerGif(location, texture);
/*    */         
/* 54 */         for (int i = 0; i < frames; i++) {
/* 55 */           BufferedImage buffer = (BufferedImage)((Tuple)gifImages.get(i)).func_76340_b();
/* 56 */           int delay = ((Integer)((Tuple)gifImages.get(i)).func_76341_a()).intValue();
/*    */           
/* 58 */           texture.add(delay, MipmapTexture.bytesFromBuffer(buffer));
/*    */         } 
/* 60 */         texture.calculateDuration();
/* 61 */       } catch (Exception e) {
/* 62 */         e.printStackTrace();
/*    */       } 
/*    */     }
/*    */     
/* 66 */     GifTexture.bindTexture(location, ticks, partialTicks);
/*    */   }
/*    */   
/*    */   private static List<Tuple<Integer, BufferedImage>> getGIFImages(InputStream inputStream) throws NullPointerException {
/* 70 */     GifDecoder decoder = new GifDecoder();
/*    */     
/* 72 */     int status = decoder.read(inputStream);
/*    */     
/* 74 */     IOUtils.closeQuietly(inputStream);
/* 75 */     if (status != GifDecoder.STATUS_OK || decoder.getFrameCount() == 0) {
/* 76 */       throw new NullPointerException();
/*    */     }
/* 78 */     List<Tuple<Integer, BufferedImage>> list = new ArrayList<>();
/*    */     
/* 80 */     for (int i = 0; i < decoder.getFrameCount(); i++) {
/* 81 */       list.add(new Tuple(Integer.valueOf(decoder.getDelay(i)), decoder.getFrame(i)));
/*    */     }
/* 83 */     return list;
/*    */   }
/*    */ }


/* Location:              D:\fanbian\[D][龙之核心]DragonCore-2.6.0.3.jar!\blockbuste\\utils\texture\GifHandler.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */